export default {
  /**
   * 存储localStorage
   */
  set(name, content) {
    if (!name) return;
    if (typeof content !== 'string') {
      content = JSON.stringify(content);
    }
    window.localStorage.setItem(name, content);
  },

  /**
   * 获取localStorage
   */
  get(name) {
    if (!name) return;
    let content = window.localStorage.getItem(name);
    try {
      return JSON.parse(content);
    } catch (err) {
      return content;
    }
  },

  /**
   * 删除localStorage
   */
  remove(name) {
    if (!name) return;
    window.localStorage.removeItem(name);
  },
  /**
   * 清除
   */
  clear() {
    window.localStorage.clear();
  }
};
